﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace ViewModel
{
    public class RelayCommand : ICommand
    {
        public RelayCommand(Func<bool> testBool, Action executeMe)
        {
            if ((testBool == null | executeMe == null))
                throw new ArgumentException("Both arguments in RelayComand constructor should not be null.");
            _canExecute = testBool;
            _executeThis = executeMe;
        }

        private Func<bool> _canExecute;
        private Action _executeThis;

        public bool CanExecute(object parameter)
        {
            return _canExecute();
        }

        public void Execute(object parameter)
        {
                if (CanExecute(_canExecute))
                    _executeThis();
        }

        public event EventHandler CanExecuteChanged;
    }
}
